﻿using MediatR;
using Warehouse.API.Applcation.Command.AllocateCommand;
using Warehouse.API.Applcation.Command.InjureCommand;
using Warehouse.Infrstructre.Interface;

namespace Warehouse.API.Applcation.CommandHandlers.AllocateCommandHandlers
{
    public class AllocateDelCommandHandlers : IRequestHandler<AllocateDelCommand, int>
    {
        private readonly IAllocateRepository _allocateRepository;
        public AllocateDelCommandHandlers(IAllocateRepository _allocateRepository)
        {
            this._allocateRepository = _allocateRepository;
        }   
        public async Task<int> Handle(AllocateDelCommand request, CancellationToken cancellationToken)
        {
            var list = (await _allocateRepository.GetAllAsyns()).Where(c => request.AllocateId.Contains(c.AllocateId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await _allocateRepository.UpdateAsync(item);
            }
            return 1;
        }
    }
}
